const express = require('express');
const router = express.Router();
const renewApplicationController = require('../controllers/renewApplicationController');
const { authenticateToken, authenticateAdmin } = require('../middleware/auth');
const { adminLogger } = require('../middleware/adminLogger');

// ===== 用户端接口 =====
router.post(
  '/apply',
  authenticateToken,
  renewApplicationController.submitRenewApplication
);

router.get(
  '/my-applications',
  authenticateToken,
  renewApplicationController.getUserRenewApplications
);

router.delete(
  '/:id/cancel',
  authenticateToken,
  renewApplicationController.cancelRenewApplication
);

// ===== 管理员端接口 =====
router.get(
  '/admin/all',
  authenticateAdmin,
  renewApplicationController.getAllRenewApplications
);

router.post(
  '/admin/:id/approve',
  authenticateAdmin,
  adminLogger('approve_renew', (req) => `批准续借申请ID: ${req.params.id}`),
  renewApplicationController.approveRenewApplication
);

router.post(
  '/admin/:id/reject',
  authenticateAdmin,
  adminLogger('reject_renew', (req) => `拒绝续借申请ID: ${req.params.id}`),
  renewApplicationController.rejectRenewApplication
);

router.get(
  '/admin/stats',
  authenticateAdmin,
  renewApplicationController.getRenewApplicationStats
);

module.exports = router;

